package junits.exception_tests;

import com.hedl.practice.diyJava.junit.study_exception_tests.test.Factorial;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertThrows;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class Main {

    @Test
    public void testNegative(){
        /**
         * 可以这样写：
         *      assertThrows(IllegalArgumentException.class,new Executable(){
         *          @Override
         *         public void execute() throws Throwable {
         *             Factorial.fact(-1);
         *         }
         *      });
         * 这里的Executable是package org.junit.jupiter.api.function;包下的；
         */
        assertThrows(IllegalArgumentException.class,()->{
           Factorial.fact(-10);
        });
    }
}
